package com.gameone;

import java.util.Random;
//import android.graphics.Rect;
//---
import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Sprite {
	private static final int MAX_SPEED = 5;
	private int xSpeed;
	private int ySpeed;
	private int x = 0;
	private int y = 0;
	private GameView gameView;
	private Bitmap bmp;

	public Sprite(GameView gameView, Bitmap bmp) {
		this.gameView = gameView;
		this.bmp = bmp;
		Random rnd = new Random();
		x = rnd.nextInt(gameView.getWidth() - bmp.getWidth());
		y = rnd.nextInt(gameView.getHeight() - bmp.getHeight());
		xSpeed = rnd.nextInt(MAX_SPEED * 2) - MAX_SPEED;
		ySpeed = rnd.nextInt(MAX_SPEED * 2) - MAX_SPEED;
	}

	public Sprite() {

	}

	private void update() {

		if (x + xSpeed < 0)
			xSpeed = 10;
		if (x + xSpeed > gameView.getWidth() - bmp.getWidth())
			xSpeed = -10;
		if (y + ySpeed < 0)
			ySpeed = 10;
		if (y + ySpeed > gameView.getHeight() - bmp.getHeight())
			ySpeed = -10;
		x = x + xSpeed;
		y = y + ySpeed;
		
		if (collision()){
			y = 0;
			x = 0;
			xSpeed=0;
			ySpeed=0;}
	}
	
	private boolean collision() {
		return false;
		
	}
	
	
	public void onCollision(){
		y = 0;
		x = 0;
		xSpeed=0;
		ySpeed=0;
	}
	public void onDraw(Canvas canvas) {
		update();
		canvas.drawBitmap(bmp, x, y, null);
	}
}
/*
 * if (x > gameView.getWidth() - bmp.getWidth() - xSpeed) { xSpeed = -5; } if (x
 * + xSpeed< 0) { xSpeed = 5; } x = x + xSpeed;
 */
